using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using System.Linq.Expressions;
using Rotempco.Core.ORM.Logic;
using Rotempco.Core.Objects;

namespace Rotempco.Core.Logic
{
    public static class GenericCloner<TSource, TDestination> where TDestination : new()
    {
        public static TDestination Clone(TSource source, bool softClone = false)
        {
            TDestination destination = new TDestination();
            Clone(source, destination, softClone: softClone);
            return destination;
        }

        public static void Clone(TSource source, TDestination destination, bool softClone = false)
        {
            GenericClonerLogic.Clone<TSource, TDestination>(source, destination, null, softClone);
        }

        public static List<TDestination> Clone(List<TSource> source, bool softClone = false)
        {
            List<TDestination> destination = new List<TDestination>();
            source.ForEach(i => destination.Add(Clone(i, softClone: softClone)));
            return destination;
        }

        public static CloningExpression<TSource, TDestination> CloneX(TSource instance, bool softClone = false)
        {
            List<TSource> instanceList = new List<TSource>();
            instanceList.Add(instance);
            return CloneX(instanceList, softClone);
        }

        public static CloningExpression<TSource, TDestination> CloneX(List<TSource> instanceList, bool softClone = false)
        {
            return new CloningExpression<TSource, TDestination>(instanceList, softClone, new List<System.Linq.Expressions.Expression<Func<TSource, object>>>());
        }
    }
}
